<template>
  <div class="writecomments" v-loading="loading">
    <div class="write-box">
      <div class="close" @click="close">
        <img src="../../assets/img/guanbi.svg" alt="" />
      </div>

      <div class="write-nei">
        <div class="write-top">
          <div>
            <img :src="gameList.giLogo" alt="" />
          </div>
          <div class="wtop-text">
            <div>{{ gameList.giName }}</div>
            <div>{{ gameList.gjDeveloper }}</div>
          </div>
        </div>

        <div class="write-ping">
          <div>总评：</div>
          <div>
            <el-rate v-model="value"></el-rate>
          </div>
          <div>给个评价吧~</div>
        </div>

        <div class="write-bottom">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3, maxRows: 4 }"
            placeholder="请输入内容"
            v-model="textarea"
          >
          </el-input>

          <div class="wfabu" @click="release">{{ upName }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { addComment, updComment } from "../../network/showGame";

export default {
  name: "WriteComments",
  props: {
    gameList: {},
    uid: {},
    gid: {},
    myPing: {},
  },
  data() {
    return {
      value: this.myPing.cscore / 2,
      textarea: this.myPing.ccontent,
      openw: "",
      upName: "发布",
      loading: false,
    };
  },
  created() {
    if (this.myPing != "") {
      this.upName = "修改";
    }
    console.log(this.myPing);
  },
  methods: {
    close() {
      this.openw = false;
      this.$emit("childByOut", this.updateOuts);
    },

    release() {
      this.loading = true;
      if (this.myPing != "") {
        this.loading = false;
        updComment(
          this.textarea,
          this.myPing.cid,
          this.value * 2,
          this.gid
        ).then((res) => {
          console.log(res);
          this.$emit("childByOut", this.updateOuts);
          this.$store.commit("changState2");
        });
      } else {
        if (this.textarea == "" || this.value == "") {
          this.loading = false;
          this.$alert("请完善内容", "提示", {
            confirmButtonText: "确定",
          });
        } else {
          addComment(this.textarea, this.value * 2, this.gid, this.uid).then(
            (res) => {
              console.log(res);
              this.$emit("childByOut", this.updateOuts);
              this.$store.commit("changState2");
            }
          );
        }
      }
    },
  },
};
</script>

<style>
.writecomments {
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  z-index: 999;
  background-color: rgb(0, 0, 0, 0.5);
}

.write-box {
  position: relative;
  width: 4.5rem;
  height: 2.8rem;
  background-color: rgb(255, 255, 255);
  margin: 0 auto;
  border-radius: 20px;
  box-shadow: 0px 0px 0.2rem #adacac;
  margin-top: 10%;
}

.close {
  position: absolute;
  width: 0.3rem;
  height: 0.3rem;
  border-radius: 50%;
  right: -0.1rem;
  top: -0.1rem;
  cursor: pointer;
}

.close img {
  width: 100%;
  height: 100%;
}

.write-nei {
  width: 90%;
  margin: 0 auto;
  padding-top: 0.25rem;
}

.write-top {
  display: flex;
  border-bottom: 1px solid rgb(233, 233, 233);
  padding-bottom: 0.1rem;
}

.write-top img {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 10px;
}

.wtop-text {
  margin-left: 0.1rem;
}

.wtop-text div:nth-child(1) {
  font-size: 0.1rem;
  padding-top: 0.05rem;
  padding-bottom: 0.1rem;
}

.wtop-text div:nth-child(2) {
  font-size: 0.08rem;
}

.write-ping {
  display: flex;
  padding: 0.2rem 0 0.2rem 0;
  align-items: center;
  border-bottom: 1px solid rgb(233, 233, 233);
}

.write-ping div:nth-child(1) {
  font-size: 0.1rem;
}
.write-ping div:nth-child(2) {
  transform: translateY(-10%);
}

.write-ping div:nth-child(2) i {
  font-size: 0.15rem;
}

.write-ping div:nth-child(3) {
  font-size: 0.08rem;
  margin-left: 0.1rem;
  color: #adacac;
}

.write-bottom {
  margin-top: 0.1rem;
}

.write-bottom textarea {
  border: none;
}

.wfabu {
  font-size: 0.1rem;
  width: 0.5rem;
  height: 0.2rem;
  line-height: 0.2rem;
  background-color: rgb(35, 173, 229);
  text-align: center;
  color: #fff;
  border-radius: 5px;
  margin-left: 88%;
  margin-top: 0.05rem;
  cursor: pointer;
}
</style>